package com.codi.bus.core.sys.dao.impl;

import com.codi.base.dao.BaseDAOImpl;
import com.codi.base.dao.PageImpl;
import com.codi.base.dao.plugin.page.PageView;
import com.codi.bus.core.sys.dao.OrganFileDao;
import com.codi.bus.core.sys.domain.OrgFile;
import com.codi.bus.core.sys.vo.OrgFileVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangzhenhao on 2017/9/18.
 */
@Repository("organFileDao")
public class OrganFIleDaoImpl extends BaseDAOImpl<OrgFile> implements OrganFileDao {


    @Override
    public Page<OrgFileVo> query(Pageable pageReq) {
        PageView pageView = getPageView(pageReq.getPageNumber(), pageReq.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("pageView", pageView);

        List<Map<String, Object>> orgFileResult = getSqlSession().selectList(generateStatement("queryByPage"), map);

//        List<Map<String, Object>> orgFiles = this.findList(this.generateStatement("queryByPage"), map);

        return new PageImpl(orgFileResult, pageReq, pageView.getRowCount());
    }

    @Override
    public Page<OrgFileVo> search(Pageable pageReq, String content) {
        PageView pageView = getPageView(pageReq.getPageNumber(), pageReq.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("pageView", pageView);
        map.put("search", content);

        List<Map<String, Object>> orgFileResult = getSqlSession().selectList(generateStatement("querySearch"), map);


        return new PageImpl(orgFileResult, pageReq, pageView.getRowCount());
    }

    @Override
    public OrgFile selectByPrimaryKey(Long fileId) {
        return this.getObject(generateStatement("selectByPrimaryKey"), fileId);
    }

    @Override
    public int updateByPrimaryKey(OrgFile orgFile) {
        return this.update(this.generateStatement("updateByPrimaryKeySelective"), orgFile);
    }
}
